import { Component, OnInit } from '@angular/core';
import { Http } from '@angular/http';
import { Observable } from 'rxjs';
import "rxjs/Rx";
import { SysUserServiceService } from '../../services/sys-user-service.service';
import { ANIMATION_TYPES } from 'ngx-loading';

@Component({
  selector: 'user-list',
  templateUrl: './user-list.component.html',
  styleUrls: ['./user-list.component.css']
})
export class UserListComponent implements OnInit {

  config: object; // loading組件配置對象

  sysUserLists = [];

  constructor(
    private _http: Http,
    private _sysUserService: SysUserServiceService
  ) { }

  ngOnInit() {
    this.config = {
      animationType: ANIMATION_TYPES.rectangleBounce,
      backdropBorderRadius: '0px',
      fullScreenBackdrop: true,
      secondaryColour: 'red'
    }
    this.get_all_sys_user();

  }

  /** 获取所有的用户数据  */
  get_all_sys_user() {
    this._sysUserService.getAll().subscribe(
      result => {
        this.sysUserLists = result['data'];
      }
    );
  }

  /** 编辑用户信息 */
  on_edit_sysUser(sysUser: any) {
    alert("TODO：编辑用户信息，控制台可以查看参数");
    console.log(sysUser);
  }

  /** 删除用户信息 */
  on_delete_sysUser(sysUser: any) {
    alert("TODO：删除用户信息，控制台可以查看参数");
    console.log(sysUser);
  }

}
